#include <stdio.h>

#define MAX_SIZE 10001

int checkRoot(int[],int);
int getComponent(int[],int);
void networkInit(int[],int);
void unionNet(int[],int,int);
int main(void){
	int network[MAX_SIZE];
	int computers;
	scanf("%d",&computers);
	char cmd;
	int c1,c2;
	networkInit(network,computers);
	do{
		while( getc(stdin) != '\n' );
		scanf("%c",&cmd);
		switch(cmd){
			case 'C':
				scanf("%d %d",&c1,&c2);
				if( checkRoot(network,c1) ==
						checkRoot(network,c2) )
					printf("yes\n");
				else
					printf("no\n");
				break;
			case 'I':
//printf("I\n");
				scanf("%d %d",&c1,&c2);
				int r1,r2;
				r1=checkRoot(network,c1);
				r2=checkRoot(network,c2);
				unionNet(network,r1,r2);
//printf("what\n");
				break;

			case 'S':
				int part=getComponent(network,computers);
				if( 1 == part )
					printf("The network is connected.\n");
				else
					printf("There are %d components.\n",part);
				break;
			default:
				printf("???\n");
		}
	}while( 'S' != cmd );
	return 0;
}

void networkInit(int network[],int size){
	for(int i=1;i<=size;i++){
		network[i]=-1;
	}
}

int checkRoot(int network[],int pc){
	while( network[ pc ] > 0 ){
		pc = network[ pc ];
	}
	return pc;
}

int getComponent(int network[],int size){
	int count=0;
	for(int i=1;i<=size;i++){
		if( -1 >= network[i] )
			count++;
	}
	return count;
}

void unionNet(int network[],int r1,int r2){
	int n1,n2;
	n1=network[r1];
	n2=network[r2];
	if( n1 <= n2 ){
		network[ r2 ] = r1;
		network[ r1 ] = n1 + n2 ;
	}else{	// n1 > n2 
		network[ r1 ] = r2;
		network[ r2 ] = n1 + n2 ;
	}
//printf("finish\n");
	return;
}
